package com.example.yemiantiaozhuan;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterViewFlipper;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toolbar;

public class BActivity extends Activity {
private Button hui;
    private Button nqy;
private Toolbar toolbar;
    private MediaPlayer player;
    private AdapterViewFlipper lunbo;
    private int[] image=new int[]{
            R.mipmap.snf,R.mipmap.nqy,R.mipmap.nqy1,
            R.mipmap.nqy2,R.mipmap.nqy3};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_b);
        nqy=(Button)findViewById(R.id.nqy);
        hui=(Button)findViewById(R.id.hui);
        //创建一个BaseAdapter对象，该对象负责提供Gallery所显示的列表项
        lunbo=(AdapterViewFlipper)findViewById(R.id.lunbo);
        BaseAdapter adapter= new BaseAdapter() {
            @Override
            public int getCount() {
                return image.length;
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView imageView=new ImageView(BActivity.this);
                imageView.setImageResource(image[position]);
                //设置ImageView的缩放类型
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                //为ImageView设置布局参数
                imageView.setLayoutParams(new ViewGroup.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
                return imageView;
            }
        };
        lunbo.setAdapter(adapter);
        lunbo.startFlipping();
        playAudio();

        hui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(BActivity.this,AActivity.class);
                startActivity(intent);
            finish();}

        });
    }

    private void playAudio() {
        try {
            player = MediaPlayer.create(this, R.raw.nanqingyuan);
            player.start();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  catch (Exception e) {
            e.printStackTrace();
        }

    }
    protected void onDestroy() {
        super.onDestroy();
        if (player!=null){
            player.release();
            player=null;
        }
    }
}